<!--
 * @Author: wangding
 * @Date: 2020-10-22 17:14:47
 * @LastEditTime: 2021-01-26 16:30:17
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \solaxcloud\src\views\system\role\add.vue
-->
<template>
    <div>
        <el-dialog
            :title="$t('add')"
            :visible="roleVisible"
            width="600px"
            @close="()=>{$store.commit('setRoleVisible',false)}">
            <el-form ref="form" :model="form" label-width="120px" >
                <el-row :gutter="20">
                    <el-col :span="16" :offset="3">
                        <el-form-item :label="$t('role.roleName')" prop="roleName" :rules="[{ required: true, message: $t('index_js_notNull')}]">
                            <el-input v-model="form.roleName" :placeholder="$t('common.info.pl-insert-content')"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="20">
                    <el-col :span="16" :offset="3">
                        <el-form-item :label="$t('role.roleNumber')" prop="roleNumber" :rules="[{ required: true, message: $t('index_js_notNull')}]" >
                            <el-select v-model="form.roleNumber" filterable  :placeholder="$t('index.selectStates')">
                                <el-option
                                v-for="item in userCodeList"
                                :key="item.value"
                                :label="item.code"
                                :value="item.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="()=>{$store.commit('setRoleVisible',false)}">{{$t('cancel')}}</el-button>
                <el-button type="primary" @click="save('form')">{{$t('sure')}}</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
export default {
    components: {

    },
    props: {
        userCodeList:{
            type:Array,
            default:() => {return []}
        },
    },
    data() {
        return {
            form:{
                roleName:'',
                roleNumber:''
            }
        };
    },
    computed: {
        roleVisible(){
            return this.$store.state.sysStore.roleVisible
        }
    },
    watch: {

    },
    created() {

    },
    mounted() {

    },
    methods: {
        save(formName){
            this.$refs[formName].validate((valid) => {
              if (valid) {
                  this.roleAddEntity()
              } else {
                console.log('error submit!!');
                return false;
              }
            });
        },
        async roleAddEntity(){
            let res = await this.API.roleAddEntity(Object.assign({},this.form,{enableFlag: 1,deleteFlag: 0}))
            this.$store.commit('setRoleVisible',false)
            this.$emit('uploadPage',true)
        }
    },
};
</script>

<style  lang="less">
    .el-dialog__body{
        // display: inline-block;
        // margin: 0 auto;
    }
</style>
